package com.igfd.tanmao.mapper;

import com.igfd.tanmao.pojo.TamllOrder;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.Date;

@Mapper
public interface TanmaoOrderMapper {

    @Insert("insert into tanmao_order(tid, status, totalQuantity, total_fee, payment, discount_fee, adjust_fee, created" +
            ", pay_time, receiver_name, receiver_state, receiver_address, receiver_mobile, created_at, updated_at) " +
            "values(#{tid}, #{status}, #{totalQuantity}, #{totalFee}, #{payment}, #{discountFee}, #{adjustFee}, #{created}" +
            ", #{payTime}, #{receiverName}, #{receiverState}, #{receiverAddress}, #{receiverMobile}, #{createdAt}, #{updatedAt})")
    int add(@Param("tid") String tid, @Param("status") String status, @Param("totalQuantity") String totalQuantity, @Param("totalFee") String totalFee, @Param("payment") String payment, @Param("discountFee") String discountFee, @Param("adjustFee") String adjustFee, @Param("created") String created,
            @Param("payTime") String payTime, @Param("receiverName") String receiverName, @Param("receiverState") String receiverState, @Param("receiverAddress") String receiverAddress, @Param("receiverMobile") String receiverMobile, @Param("createdAt") Date createdAt, @Param("updatedAt") Date updatedAt);

    @Select("select count(*) from tanmao_order where tid = #{tid}")
    int findTanmaoOrderCount(@Param("tid") String tid);

    @Update("update tanmao_order set status = #{status},updated_at = #{updatedAt} where tid = #{tid}")
    int updateTanmaoOrderByTid(@Param("status") String status,@Param("updatedAt") Date updatedAt,@Param("tid") String tid);

    @Select("select * from tanmao_order where tid = #{tid}")
    TamllOrder findTanmaoOrderByTid(@Param("tid") String tid);

    @Select("select tid from tanmao_order where sync_status = 0" +
            " and status in ('WAIT_BUYER_PAY','WAIT_SELLER_SEND_GOODS','WAIT_BUYER_CONFIRM_GOODS','TRADE_BUYER_SIGNED','TRADE_FINISHED')")
    ArrayList<TamllOrder> findTanmaoOrderAllNoSync();
}
